﻿import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import ConfigElementType 1.0
import "qrc:/qmlComponents/ConfigManager"
import "qrc:/qmlComponents/AxisModulePos"
import "qrc:/qmlComponents/VisionViewer"
import "qrc:/qmlComponents/CustomizedUIElement"

Item {
    RowLayout{
        spacing: 20

        ObjectEditor{
            Layout.alignment: Qt.AlignTop
            sectionName: "DispenserConfig"
            configModel: dispensorConfig
            listMaxHeight: 300
            Component.onCompleted: {
                init()
            }
        }

        ColumnLayout{
            Layout.alignment: Qt.AlignTop
            spacing: 40
            ObjectEditor{
                sectionName: "GlueCheckParam"
                configModel: glueCheckParam
                listMaxHeight: 300
                Component.onCompleted: {
                    init()
                }
            }
            GroupBox{
                title: qsTr("DispenseShapeBaseOnCurrentPos")
                ColumnLayout{
                    RowLayout{
                        Label{
                            text: qsTr("LineLen:")
                        }
                        MyDoubleInput{
                            id: txtLineLen
                            text: qsTr("30")
                        }
                    }
                    Button{
                        text: qsTr("ShotGlueLine")
                        onClicked: {
                            tem.runSingleCmd(aaHead, "shotGlueLine", [txtLineLen.text])
                        }
                    }
                    RowLayout{
                        Label{
                            text: qsTr("RectWidth:")
                        }
                        MyDoubleInput{
                            id: txtRectWidth
                            text: qsTr("4")
                        }
                    }
                    RowLayout{
                        Label{
                            text: qsTr("RectHeight:")
                        }
                        MyDoubleInput{
                            id: txtRectHeight
                            text: qsTr("3")
                        }
                    }
                    Button{
                        text: qsTr("ShotRectangle")
                        onClicked: {
                            tem.runSingleCmd(aaHead, "shotRectangle", [txtRectWidth.text, txtRectHeight.text])
                        }
                    }
                }
            }
        }

        ColumnLayout{
            Layout.alignment: Qt.AlignTop
            ConfigRow{
                configName: "shotterSoftLandHeight"
                configModel: aaConfig
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }

            ConfigRow{
                configName: "shotGlueOffsetZ"
                configModel: aaConfig
                Component.onCompleted: {
                    init(ConfigElementType.Double)
                }
            }

            ConfigRow{
                configName: "dispenseParthFileName"
                configModel: aaConfig
                Component.onCompleted: {
                    init(ConfigElementType.Other)
                }
            }

            XYZModulePos{
                moduleName: "SUTXYZ"
                posName: "GluePrPos"
            }

            RowLayout{
                Button{
                    text: qsTr("SaveImage")
                    onClicked: {
                        tem.runSingleCmd(aaHead, "saveImageForEditDispPath")
                    }
                }
                Button{
                    text: qsTr("LoadPath")
                    onClicked: {
                        dispensePathResultImage.updateImage()
                        tem.runSingleCmd(aaHead, "readDispensePath")
                    }
                }
            }

            RowLayout{
                CheckBox{
                    id: ckbCheckGlue
                    text: qsTr("CheckGlue")
                }

                Button{
                    text: qsTr("ShotGlue")
                    onClicked: {
                        tem.runSingleCmd(aaHead, "shotGlue", [ckbCheckGlue.checked])
                    }
                }
            }

            ConfigRow{
                configModel: aaConfig
                configName:"actionUVTime"

                Component.onCompleted:
                {
                    autoInit()
                }
            }

            Button{
                text: qsTr("doUV")
                onClicked: {
                    tem.runSingleCmd(aaHead, "doUV")
                }
            }

            Item {
                width: 400
                height: 400
                Image {
                    id: dispensePathResultImage
                    anchors.fill: parent
                    fillMode: Image.PreserveAspectFit

                    function updateImage(){
                        var resultImage = aaHead.getDispensePathResultImageName()
                        source = ""
                        if(resultImage === ""){
                            dispensePathResultImage.source = "qrc:/commonicons/no-image.png"
                        }else{
                            dispensePathResultImage.source = resultImage
                        }
                    }

                    Component.onCompleted: {
                        updateImage()
                    }
                }
            }
        }
    }
}
